package com.wedu.modules.dss.controller;

import com.wedu.common.utils.PageUtils;
import com.wedu.common.utils.R;
import com.wedu.modules.dss.entity.dto.BatchOperationSaveDTO;
import com.wedu.modules.dss.entity.dto.OperationSaveDTO;
import com.wedu.modules.dss.service.DssOperationStatusService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/dss/operation")
public class DssOperationController {
    @Autowired
    private DssOperationStatusService dssOperationStatus;
    /**
     * 设备状态管理的查询
     * @param params
     * @return
     */
    @RequestMapping("/list")
    @RequiresPermissions("dss:operation:list")
    public R list(@RequestParam Map<String, Object> params)
    {
        PageUtils page = dssOperationStatus.queryOperationStatus(params);
        return R.ok().put("page", page);
    }



    /**
     * 与前端的修改操作相对应，修改数据库中的数据并添加新数据
     * @param dto
     * @return
     */
    @PostMapping("/save")
    @RequiresPermissions("dss:operation:save")
    public R save(@RequestBody OperationSaveDTO dto)
    {
        String deviceId = dto.getDeviceId();
        Integer lightStatus = dto.getLightStatus();
        dssOperationStatus.saveByUser(deviceId,lightStatus);
        return R.ok();
    }

    /**
     * 批量添加设备状态
     * @param batchDto
     * @return
     */
    @PostMapping("/batchSave")
    @RequiresPermissions("dss:operation:batchSave")
    public R batchSave(@RequestBody BatchOperationSaveDTO batchDto)
    {
        List<OperationSaveDTO> operationList = batchDto.getOperationList();
        dssOperationStatus.batchSaveByUser(operationList);
        return R.ok();

    }

    /**
     * 设备故障管理列表的查询
     * @param params
     * @return
     */
    @RequestMapping("/errorList")
    @RequiresPermissions("dss:error:list")
    public R list2(@RequestParam Map<String, Object> params)
    {
        PageUtils page = dssOperationStatus.queryErrorManage(params);
        return R.ok().put("page", page);
    }


}
